#pragma once

#include <queue>
#include <vector>
#include <SFML/System/Mutex.hpp>

class Sample;

typedef std::queue<Sample*> SampleQueue;
typedef std::vector<Sample*> SampleVector;

class SampleBuffer
{
public:
	SampleBuffer(void);
	~SampleBuffer(void);

	void Initialize(int chunkSize, int bufferCount, bool silenceWhenEmpty);
	Sample* Read();
	void Write(Sample* sample);
	void Reset();
	int Size();

private:
	sf::Mutex mutex;
	int chunkSize;
	int bufferCount;
	SampleQueue buffers;
	Sample* nullSample;
};

class SampleBuffer2
{
public:
	SampleBuffer2(void);
	~SampleBuffer2(void);

	void Initialize(int chunkSize, int bufferCount, bool silenceWhenEmpty);
	Sample* Read();
	void Write(Sample* sample);
	void Recycle(Sample* sample);
	void Reset();
	int Size();
	void SetActive(bool active);
	bool IsActive();

private:
	sf::Mutex mutex;
	int chunkSize;
	int bufferCount;
	SampleQueue writtenSamples;
	SampleQueue idleSamples;
	Sample* nullSample;
	bool active;
};